export const storage = {
  //存储sessionStorage
  setSession: (name, content) => {
    if (!name) return
    if (typeof content !== 'string') {
      content = JSON.stringify(content)
    }
    window.sessionStorage.setItem(name, content)
  },
  //获取sessionStorage
  getSession: (name) => {
    if (!name) return
    if (storage.isJSON(window.sessionStorage.getItem(name))) {
      return JSON.parse(window.sessionStorage.getItem(name))
    } else {
      return window.sessionStorage.getItem(name)
    }
  },
  //删除sessionStorage
  removeSession: name => {
    if (!name) return
    window.sessionStorage.removeItem(name)
  },
  isJSON(str) {
    if (typeof str == 'string') {
      try {
        var obj = JSON.parse(str);
        if (typeof obj == 'object' && obj) {
          return true;
        } else {
          return false;
        }
      } catch (e) {
        return false;
      }
    }
  }
}